package sskj.regulatory.data.response.session

import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
import sskj.regulatory.data.response.Response

class IndexDataResponse : Response() {

    @SerializedName("data")
    @Expose
    val data: Data? = null

    class Data {

        @SerializedName("version")
        @Expose
        val version: String? = null

        @SerializedName("simpleUser")
        @Expose
        val simpleUser: SessionUserResponse? = null

        @SerializedName("isPhoto")
        @Expose
        val isPhoto: Boolean = false

        @SerializedName("accessCodes")
        @Expose
        val accessCodes: Map<String, Boolean> = HashMap()

        @SerializedName("bingDings")
        @Expose
        val bingDings: List<BingDingResponse> = ArrayList()

        @SerializedName("menuData")
        @Expose
        val menuData: List<MenuDataResponse<Any>> = ArrayList()

        @SerializedName("noticeProperties")
        @Expose
        val noticeProperties: NoticePropertiesResponse? = null
    }

    fun getBingDingByRole(roleId: String): BingDingResponse? {
        return when (data?.bingDings?.isNotEmpty()) {
            true -> data.bingDings.singleOrNull { it.roleId == roleId }
            false -> null
            null -> null
        }
    }

    fun isBingDingRole(roleId: String): Boolean {
        return when (data?.bingDings?.isNotEmpty()) {
            true -> data.bingDings.any { it.roleId == roleId }
            false -> false
            null -> false
        }
    }

}
